/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package project;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author jon
 */
public class Client {
    private int client_number;
    private String client_name;
    private String associate_name;
    private Date date;
    private double max_rent;
    private String preferred_type;
    private int branch_id;

    public Client(int client_number, String client_name, String associate_name, Date date, double max_rent, String preferred_type, int branch_name) {
        this.client_number = client_number;
        this.client_name = client_name;
        this.associate_name = associate_name;
        this.date = date;
        this.max_rent = max_rent;
        this.preferred_type = preferred_type;
        this.branch_id = branch_name;
    }


    /**
     * @return the client_number
     */
    public int getClient_number() {
        return client_number;
    }

    /**
     * @param client_number the client_number to set
     */
    public void setClient_number(int client_number) {
        this.client_number = client_number;
    }

    /**
     * @return the client_name
     */
    public String getClient_name() {
        return client_name;
    }

    /**
     * @param client_name the client_name to set
     */
    public void setClient_name(String client_name) {
        this.client_name = client_name;
    }

    /**
     * @return the associate_name
     */
    public String getAssociate_name() {
        return associate_name;
    }

    /**
     * @param associate_name the associate_name to set
     */
    public void setAssociate_name(String associate_name) {
        this.associate_name = associate_name;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * @return the max_rent
     */
    public double getMax_rent() {
        return max_rent;
    }

    /**
     * @param max_rent the max_rent to set
     */
    public void setMax_rent(double max_rent) {
        this.max_rent = max_rent;
    }

    /**
     * @return the preferred_type
     */
    public String getPreferred_type() {
        return preferred_type;
    }

    /**
     * @param preferred_type the preferred_type to set
     */
    public void setPreferred_type(String preferred_type) {
        this.preferred_type = preferred_type;
    }

    /**
     * @return the branch_name
     */
    public int getBranch_name() {
        return branch_id;
    }

    /**
     * @param branch_name the branch_name to set
     */
    public void setBranch_name(int branch_name) {
        this.branch_id = branch_name;
    }

    public void insert()
    {
        try
        {
            String host = "jdbc:oracle:thin:@localhost:1521:xe";
            String username = "jon";
            String password = "chaosecco";
            String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);

            Connection connection = DriverManager.getConnection(host,
                    username, password);
            System.out.print("Connected successfully.");
            String insertQuery = "INSERT INTO CLIENT(" +
                    "client_number, " +
                    "client_name, " +
                    "associate_name, " +
                    "client_date, " +
                    "max_rent, " +
                    "preferred_type, "  +
                    "branch_id)" +
                    "VALUES(?, ?, ?, ?, ?, ?, ?)";
            PreparedStatement ps = connection.prepareStatement(insertQuery);
            ps.setInt(1, client_number);
            ps.setString(2, client_name);
            ps.setString(3, associate_name);
            ps.setDate(4, date);
            ps.setDouble(5, max_rent);
            ps.setString(6, preferred_type);
            ps.setInt(7, branch_id);
            ps.executeUpdate();

            connection.close();
        }

        catch (SQLException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }

        catch(ClassNotFoundException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }
    }
}
